﻿using System.Collections.Generic;
using NUnit.Framework;
using SpecFlowTfsLinker.Cleaner;
using SpecFlowTfsLinker.Entities;
using SpecFlowTfsLinker.Test.Common;

namespace SpecFlowTfsLinker.Test.Cleaner
{
    [TestFixture]
    public class StatementCleanerTest : TestInitialization
    {
        private const string StandardStatement = "{0} something";
        private const string StatementWithSpaceBefore = " {0} something";
        private const string StatementWithMultipleSpaceBefore = "{0}     something    ";
        private const string StatementWithoutSpace = "{0}something";
        private const string ExpectedStatement = "something";

        private readonly List<string> _statementPatterns = new List<string>
                                                           {
                                                               StandardStatement,
                                                               StatementWithMultipleSpaceBefore,
                                                               StatementWithoutSpace,
                                                               StatementWithSpaceBefore
                                                           };

        [Test]
        public void CanCleanStatements()
        {
            ApplyCleanerWithDifferentStatementFor(StatementType.Given.ToString());
            ApplyCleanerWithDifferentStatementFor(StatementType.When.ToString());
            ApplyCleanerWithDifferentStatementFor(StatementType.And.ToString());
            ApplyCleanerWithDifferentStatementFor(StatementType.Then.ToString());
        }

        [Test]
        public void CanCleanUpperAndLowerStatements()
        {
            ApplyCleanerWithDifferentStatementFor("gIVeN");
            ApplyCleanerWithDifferentStatementFor("wHeN");
            ApplyCleanerWithDifferentStatementFor("tHeN");
            ApplyCleanerWithDifferentStatementFor("aNd");
        }

        [Test]
        public void CanTransformWordCharacter()
        {
            Assert.That(new StatementCleaner("This ‘is’ really, a « wonderful » idea, isn’t it? …").Clean(), Is.EqualTo("This 'is' really, a \"wonderful\" idea, isn't it? ..."));
        }

        private void ApplyCleanerWithDifferentStatementFor(string specFlowstatement)
        {
            _statementPatterns.ForEach(statement =>
                                       {
                                           var formatedStatement = string.Format(statement, specFlowstatement);
                                           var cleanedStatement = new StatementCleaner(formatedStatement).Clean();
                                           Assert.That(ExpectedStatement, Is.EqualTo(cleanedStatement));
                                       });
        }
    }
}